<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue计算属性，方法，侦听器</title>
    <script src="../vue.js"></script>
</head>
<body>
    <div id="app">
       {{fullName}}
       {{age}}
    </div>
    
    <script>
        //原生
       // var dom = document.getById('app');
       // dom.innerHtml = 'hello word';
       var app = new Vue({
           el:"#app",
           data:{
               firstname:'hello word',
               lasttname:'tom',
               fullName:'',
               age:21
           },
           //  侦听器 
           watch: {           
               firstname: function(){
                    console.log('计算了一次');
                   this.fullname = this.firstname + "" +this.lasttname;
               },
               lasttname: function(){
                    console.log('计算了一次');
                   this.fullname = this.firstname + "" +this.lasttname;
               },
           }

           //  方法计算  插值表达式{{fullName()}}
        //    methods:{
        //     fullName: function(){
        //             console.log('计算了一次');
        //             return this.firstname + "" +this.lasttname
        //         }
        //    },
           //计算属性  内置缓存的  改变时会计算
        //    computed: {
        //         fullName: function(){
        //             console.log('计算了一次');
        //             return this.firstname + "" +this.lasttname
        //         }
        //    }
       });
       
    </script>
</body>
</html>